const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const Site = sequelize.define('Site', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  name: {
    type: DataTypes.STRING(100),
    allowNull: false
  },
  domain: {
    type: DataTypes.STRING(255),
    allowNull: false,
    unique: true
  },
  subdomain: {
    type: DataTypes.STRING(100),
    allowNull: true
  },
  template: {
    type: DataTypes.STRING(50),
    defaultValue: 'default'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive', 'maintenance'),
    defaultValue: 'active'
  },
  config: {
    type: DataTypes.JSON,
    defaultValue: {}
  },
  seoConfig: {
    type: DataTypes.JSON,
    defaultValue: {
      title: '',
      description: '',
      keywords: [],
      robots: 'index,follow'
    }
  },
  sslEnabled: {
    type: DataTypes.BOOLEAN,
    defaultValue: false
  },
  cdnEnabled: {
    type: DataTypes.BOOLEAN,
    defaultValue: false
  },
  analyticsCode: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'sites',
  timestamps: true,
  indexes: [
    {
      unique: true,
      fields: ['domain']
    },
    {
      fields: ['status']
    }
  ]
});

module.exports = Site;
